/**
 * Created by dio on 2017/2/21 0021.
 */

import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import Util from "../../Util";
import SwitchTextItem from "../common/SwitchTextItem";
import SingleSelectionTextItem from "../common/SingleSelectionTextItem";
import InputTextItem from "../common/InputTextItem";
import WarrantyOilCheck from "./WarrantyOilCheck";
import NextButton from "../common/NextButton";
import {ActionConst, Actions} from "react-native-router-flux";

export default class ExternalEngineCheck extends React.Component {
    // 构造函数，可执行初始化操作
    constructor(props) {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {};
        if (!Util.selectCar.externalenginecheck) {
            Util.selectCar.externalenginecheck = [
                {value: Util.selectCar.basicinfo.vehiclevincode.value, name: "车辆VIN码"},
                {value: "否", name: "发动机舱气味检查"},
                {value: "否", name: "发动机舱线束布置规整检查"},
                {value: "正常", name: "发动机舱水管线束检查"},
                {value: "正常", name: "水管与发动机缸体连接处渗漏检查"},
                {value: "正常", name: "气门室盖垫渗漏检查"},
                {value: "正常", name: "水箱、冷却液渗漏检查"},
                {value: "正常", name: "发动机缸体渗漏检查"},
                {value: "正常", name: "发动机机油加注口黏着物检查"},
                {value: "否", name: "发动机油底壳渗漏检查"},
                {value: "正常", name: "变速箱渗漏检查"},
                {value: "否", name: "发动机改装检查"},
                {value: "否", name: "气门室盖螺丝扭动痕迹检查"},
                {value: "否", name: "发动机缸体螺丝扭动痕迹检查"},
                {value: "否", name: "发动机支架螺丝扭动痕迹检查"},
                {value: "否", name: "变速箱与发动机连接处螺丝扭动痕迹检查"},
                {value: "否", name: "变速箱油底壳螺丝扭动痕迹检查"},
                {value: "否", name: "发动机油底壳螺丝扭动痕迹检查"}
            ];
        }
    }

    // 组件被渲染时
    render() {
        return (
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='发动机外部检查(01)' clickedLeft={this.clickedBack.bind(this)} leftText='返回'
                                    clickedRight={this.clickedNew.bind(this)} rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        Util.selectCar.externalenginecheck.map((item, i) => this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={() => this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i) {
        switch (i) {
            case 0:
                return (<InputTextItem object={item} autoCapitalize={'characters'} keyboardType={'default'}
                                       maxLength={17}/>);
            case 1:
                return (<SingleSelectionTextItem object={item}
                                                 optionArray={[{name: "否"}, {name: "有机油味"}, {name: "有汽油味"}, {name: "有烧焦味"}, {name: "其它"}]}/>);
            case 2:
                return (<SwitchTextItem object={item} onValue='是' offValue='否'/>);
            case 3:
                return (<SingleSelectionTextItem object={item}
                                                 optionArray={[{name: "正常"}, {name: "老化"}, {name: "龟裂"}, {name: "破损"}]}/>);
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                return (
                    <SingleSelectionTextItem object={item} optionArray={[{name: "正常"}, {name: "浸湿"}, {name: "渗漏"}]}/>);
            case 9:
                return (<SingleSelectionTextItem object={item}
                                                 optionArray={[{name: "否"}, {name: "胶质物"}, {name: "黄色黏着物"}]}/>);
            case 10:
                return (
                    <SingleSelectionTextItem object={item} optionArray={[{name: "正常"}, {name: "浸湿"}, {name: "渗漏"}]}/>);
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
                return (<SwitchTextItem object={item} onValue='是' offValue='否'/>);
        }
    }

    clickedBack() {
        Actions.pop();
    }

    clickedNew() {
        Util.saveData('cars', Util.selectCar);
        Actions.WarrantyOilCheck(
            {
                type: ActionConst.PUSH_OR_POP,
                name: 'WarrantyOilCheck',
                component: WarrantyOilCheck,
            }
        );
    }
}